#include <Timestamp.h>

namespace AsyncLogger {
	long long Timestamp::getCurrTimestamp()
	{
		auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
		return ms.count();
	}

	std::string Timestamp::getFormatDate()
	{
		auto now = std::chrono::system_clock::now();
		auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) - std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch());
		std::time_t tt = std::chrono::system_clock::to_time_t(now);
		std::tm* ptm = std::localtime(&tt);
		char buf[64] = { 0 };
		sprintf(buf, "%d%0.2d%0.2d %0.2d::%0.2d::%0.2d %lld", 1900 + ptm->tm_year, 1 + ptm->tm_mon, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, ms.count());
		return buf;
	}

	const long long& Timestamp::getTimestamp()
	{
		return timestamp_;
	}
}
